//
//  ST_MyCenterLittleValueItemControl.swift
//  btvideo
//
//  Created by mac on 2020/10/10.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_MyCenterLittleValueItemControl: UIControl {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.init(hex: 0xF5F8FA)
        self.cornerRadius = 10
        
        self.addSubview(right_image_view)
        self.addSubview(titleLabel)
        self.addSubview(content_label)
        self.addSubview(content_unit_label)
        
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(5)
            make.height.equalTo(18)
        }
        
        right_image_view.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.right).offset(2)
            make.centerY.equalTo(titleLabel)
            make.width.height.equalTo(16)
        }
        
        content_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(25)
            make.height.equalTo(31)
        }
        
        content_unit_label.snp.makeConstraints { (make) in
            make.bottom.equalTo(content_label).offset(-3)
            make.left.equalTo(content_label.snp.right).offset(0)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    fileprivate lazy var right_image_view:UIImageView = {
         let control = UIImageView()
          control.contentMode = .scaleAspectFill
          return control
      }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor(hexString: "#BEC4CF")
        control.font = UIFont.systemFont(ofSize: 13, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = "0"
        control.textColor = UIColor(hexString: "#333333")
        control.font = UIFont.init(name: "DINPro-Black", size: 24)
        return control
    }()
    
    fileprivate lazy var content_unit_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor(hexString: "#C6CAD5")
        control.font = UIFont.systemFont(ofSize: 11, weight: UIFont.Weight.regular)
        return control
    }()
    
    var data:(title:String,imageName:String,unitStr:String)?{
        didSet{
            
            guard let d = data else { return  }
            
            titleLabel.text = d.title
            
            content_unit_label.text = d.unitStr
            
            if let img = UIImage.init(named: d.imageName){
                right_image_view.image = img
            }else{
                right_image_view.pin_setImage(from: d.imageName.url)
            }
            
        }
    }
    
    var numbervalue = 0{
        didSet{
            
            #if DEBUG
                content_label.text = numbervalue.string
            #else
                if numbervalue < 10000 {
                    content_label.text = numbervalue.string
                }else{
                    
                    let w = numbervalue.float / 10000.0

                    content_label.text = String.init(format: "%.1f", w) + "W"
                }
            #endif
        }
    }
    
    var number_doublevalue = 0.double{
        didSet{
            
            #if DEBUG
                content_label.text = String.init(format: "%.2f", number_doublevalue)
            #else
                if numbervalue < 10000 {
                    content_label.text = String.init(format: "%.2f", number_doublevalue)
                }else{
                    content_label.text = String.init(format: "%.1fW", number_doublevalue/10000.0)
                }
            #endif
            
        }
    }
    
}
